package com.imti.controller;


import com.imti.bean.DeskInfo;
import com.imti.bean.Nurse;
import com.imti.bean.pojo.NdutyVo;
import com.imti.service.DutyService;
import com.imti.service.NdutyService;
import com.imti.util.PageBean;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/nduty")
public class NdutyCtroller {

    @Autowired
    private NdutyService ndutyService;

    @Autowired
    private DutyService dutyService;

    /*护士值班页面查询*/
    @RequestMapping("/page")
    public String findAllNduty(NdutyVo ndutyVo, PageBean page, HttpServletRequest request) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("ndutyVo", ndutyVo);
        map.put("page", page);
        PageBean p = ndutyService.pageDuty(map);
        request.setAttribute("page", p);
        return "nurseDuty-list";
    }

    /*添加页面跳转*/
    @RequestMapping("/addNDuty")
    public String addNDuty(HttpServletRequest request){
        List<Nurse> nurseList = ndutyService.fillAllNurse();
        request.setAttribute("nurseList", nurseList);
        return "nurseDuty-add";
    }

    /*添加 护士值班数据*/
    @RequestMapping("/saveNDuty")
    @ResponseBody
    public String insertNduty(NdutyVo ndutyVo){
        int res = ndutyService.insert(ndutyVo);
        return res > 0 ? "1" : "0";
    }

    /*分配科室页面跳转*/
    @RequestMapping("/updateNDeskWork")
    public String updateNDeskWork(NdutyVo ndutyVo,HttpServletRequest request) {
        HashMap map = new HashMap<>();
        map.put("ndutyVo",ndutyVo);
        List<NdutyVo> ndutyVos = ndutyService.selectBy(ndutyVo);
        List<DeskInfo> allDesk = dutyService.findAllDesk();
        request.setAttribute("allDesk",allDesk);
        return "nurseDuty-updateDeskwork";
    }

    /*修改科室*/
    @RequestMapping("/saveDeskWork")
    @ResponseBody
    public String saveDeskWork(NdutyVo ndutyVo){
        int res = ndutyService.updateById(ndutyVo);
        return res > 0 ?"1":"0";
    }

    /*调班页面跳转*/
    @RequestMapping("/updateNDuty")
    public String updateNDuty(NdutyVo ndutyVo,HttpServletRequest request) {
        HashMap map = new HashMap<>();
        map.put("ndutyVo",ndutyVo);
        List<NdutyVo> ndutyVos = ndutyService.selectBy(ndutyVo);
        return "nurseDuty-update";
    }
    /*修改调班*/
    @RequestMapping("/updateNDutys")
    @ResponseBody
    public String updateNDutys(NdutyVo ndutyVo){
        int res = ndutyService.updateById(ndutyVo);
        return res > 0 ?"1":"0";
    }


}
